import axios from 'axios'
import { Notification } from 'element-ui'

// 1. 创建实例
const request = axios.create({
  baseURL: 'http://8.140.34.53:3007/',
  timeout: 5000
})

// 2. 请求拦截器
request.interceptors.request.use(config => {
  const token = localStorage.getItem('token')
  if (token) {
    config.headers['Authorization'] = 'Bearer ' + token
  }
  return config
}, error => {
  return Promise.reject(error)
})


// 3. 响应拦截器
request.interceptors.response.use(res => {
  const { code, msg, data } = res.data
  if (code === '200') return data
  Notification.error({
    title: '密码错误'
  });
  return Promise.reject(msg)
}, error => {
  return Promise.reject(error)
})


export default request 